package world.snowcrystal.commons.service.rpc;

import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import world.snowcrystal.commons.model.dto.rpc.InterfaceIdAndUserIdRequest;
import world.snowcrystal.commons.model.dto.rpc.RetrieveInterfaceInformationRequest;
import world.snowcrystal.commons.model.dto.rpc.SimpleRpcResponse;
import world.snowcrystal.commons.model.entity.InterfaceInfo;

@RequestMapping("/service/interface-info")
@FeignClient(name = "open-api-platform", path = "/api", contextId = "RpcInterfaceService")
public interface RpcInterfaceService {

    /**
     * 获取接口信息，注意，实现时如果按照给定参数找到了对应的接口，则需要继续判断
     * 接口是否正常运行
     *
     * @return 接口信息 如果接口不存在或者接口状态为非正常，则返回 null
     */
    @PostMapping("/retrieve-interface-info")
    InterfaceInfo getInterfaceInfo(@RequestBody RetrieveInterfaceInformationRequest request);

    /**
     * 增加接口调用次数
     *
     * @return true 表示操作成功
     */
    @PostMapping("/increase-interface-invoke-count")
    SimpleRpcResponse<Boolean> increaseInterfaceInvokeCount(@RequestBody InterfaceIdAndUserIdRequest request);

    /**
     * 获取接口剩余调用次数
     *
     * @return -1 表示用户没有开通该接口的调用，其他情况返回值大于等于 0
     */
    @PostMapping("/retrieve-remaining-invoke-count")
    SimpleRpcResponse<Integer> retrieveRemainingInvokeCount(@RequestBody InterfaceIdAndUserIdRequest request);


}
